package com.example.myapplication.activity;

import android.provider.Settings;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.example.myapplication.R;
import com.example.myapplication.bean.weatherinfo;
import com.example.myapplication.listener.weatherlistener;
import com.example.myapplication.mode.weathermode;

public class MainActivity extends AppCompatActivity implements View.OnClickListener,WeatherListener {
    EditText editcitynumber;
    Button button_ch,button_51;
    TextView textCityName,textTemp;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }
    void initView  (){ //初始化控件
        editcitynumber=(EditText)findViewById(R.id.edit_citynumberText);
        button_ch=(Button)findViewById(R.id.button_中国天气);
        button_51=(Button)findViewById(R.id.button_51);
        textCityName=(TextView)findViewById(R.id.text_cityname);
        textTemp=(TextView)findViewById(R.id.text_temp);
        button_ch.setOnClickListener(this);
        button_51.setOnClickListener(this);
      }
    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.button_中国天气;
                System.out.print("==>>"+"button is clicked,onClick()");
                WeatherMode mode=new WeatherMode();
                mode.getWeather(editcitynumber.getText().toString().this);
                break;
            case R.id.button_51;
                ////////////

                break;

        }
    }
    @Override
    public void onResponse(weatherInfo weatherInfo) {
        textCityName.setText(weatherInfo.getCity());
        textTemp.setText(weatherInfo.getTemp());
    }
    @Override
    public void onFailure(String message){
        textCityName.setText(message);

    }
  }
